package com.mall.alipay.service.impl;

import com.mall.alipay.entity.UserInfo;
import com.mall.alipay.entity.dto.UserDTO;
import com.mall.alipay.mapper.UserInfoMapper;
import com.mall.alipay.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    // 加密方式
    @Resource
    private PasswordEncoder passwordEncoder;

    @Resource
    private UserInfoMapper userInfoMapper;

    @Override
    public UserDTO getUserInfo(String account) {
        return userInfoMapper.getUserInfo(account);
    }

    @Override
    public int addUserInfo(UserInfo userInfo) {
        // 对密码进行加密
        userInfo.setPwd(passwordEncoder.encode(userInfo.getPwd()));
        return userInfoMapper.insert(userInfo);
    }
}
